//
//  MessagePushCell.m
//  Sports-Go
//
//  Created by rimi on 16/9/28.
//  Copyright © 2016年 YRL. All rights reserved.
//

#import "MessagePushCell.h"
#import "NotificationHelper.h"
@interface MessagePushCell ()
@property(nonatomic,strong)UILabel *label1;
@property(nonatomic,strong)UILabel *label2;
@property(nonatomic,strong)UILabel *label3;
@property(nonatomic,strong)UISwitch *switch1;

@end
@implementation MessagePushCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _dic = [NSDictionary dictionary];
        [self addSubview:self.label1];
        [self addSubview:self.label2];
        [self addSubview:self.label3];
        [self addSubview:self.switch1];
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    self.label1.frame = CGRectMake(20*bi, 5, 150*bi, 30);
    self.label2.frame = CGRectMake(20*bi, 35, 150*bi, 20);
    self.label3.frame = CGRectMake(screen_size.width-80, 15, 80, 30);
    self.switch1.frame = CGRectMake(screen_size.width-80*bi, 20, 80, 20);

}
- (void)setDic:(NSDictionary *)dic{

    _dic = dic;
    if (_index == 0) {
        self.switch1.hidden = NO;
        self.label3.hidden = YES;
        
    }else{
        self.switch1.hidden = YES;
        self.label3.hidden = NO;
    }
    self.label1.text = _dic[@"m1"];
    self.label2.text = _dic[@"m2"];
    NSString *time = [[NSUserDefaults standardUserDefaults]objectForKey:@"noticeTime"];
    if (time) {
        self.label3.text = time;
    }else{
        self.label3.text = @"16:50";
       
    }
  [self setui];  
    
    
}

- (void)setui{
    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"switch"]) {
      
    self.switch1.on = YES;
        
    }else{
    
    self.switch1.on = NO;
        
    }
   
}
- (void)switchAction:(UISwitch *)sender{
    if (sender.on) {
        [[NSNotificationCenter defaultCenter]postNotificationName:@"change" object:nil];
        [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"switch"];
        NSString *timeString = [NSString stringWithFormat:@"%@:01",self.label3.text];
        [[NotificationHelper shareInstance] addNotifiction:timeString keyA:@"key" messageA:@"可以领取体力了！" ];
        
        
    }else{
    [[NSNotificationCenter defaultCenter]postNotificationName:@"change1" object:nil];
    [[NotificationHelper shareInstance]removeLocalAllNotification];
    [[NSUserDefaults standardUserDefaults]setBool:NO forKey:@"switch"];
    }
    
}
- (UILabel *)label1{
    if (!_label1) {
        _label1 = ({
            UILabel *label = [[UILabel alloc]init];
           
            label.textColor = [UIColor blackColor];
            label.font = [UIFont boldSystemFontOfSize:17];
            label.textAlignment = NSTextAlignmentLeft;
            label;
        });
    }
    return _label1;
}
- (UILabel *)label2{
    if (!_label2) {
        _label2 = ({
            UILabel *label = [[UILabel alloc]init];
            
            label.textColor = [UIColor lightGrayColor];
            label.font = [UIFont systemFontOfSize:14];
            label.textAlignment = NSTextAlignmentLeft;
            label;
        
        });
    }
    return _label2;
}
- (UILabel *)label3{
    if (!_label3) {
        _label3 = ({
            UILabel *label = [[UILabel alloc]init];
            label.textColor = [UIColor blackColor];
            label.font = [UIFont systemFontOfSize:17];
            label.textAlignment = NSTextAlignmentLeft;
            label;
        });
    }
    return _label3;
}
- (UISwitch *)switch1{
    if (!_switch1) {
    _switch1 = [[UISwitch alloc]init];

    [_switch1 addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
        
    }

    return _switch1;
}

@end
